 var id = getvl("id");
$(function(){
        if(id!='') {
       slelectnot();
        }else{
            //alert("请传入商品id");	
         }
});//end	
var userid="";
var currentPage=1;
function chaxunwodezhuji2(){
		     if(uuuuid!=''){
		$.ajax({
		url: urlcore + "/api/myFoot/selectPage2?current="+currentPage+"&userId="+uuuuid,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				var wodezhuji="";
				$.each(data.data.list, function(y,w) {
			wodezhuji+='<dl>'+
'		<dt>'+
'	<a id="mdianhua" onclick="shangpingherf('+w.goods.id+')"><img  src="'+w.goods.coverUrl+'"/></a>'+
'		</dt>'+
'		<dd>'+
'			<h5>'+w.goods.goodsTitle+'</h5>'+
'			<h6>&yen;'+w.goods.packPrice+'</h6>'+
'		</dd>'+
'	</dl>'+
'	<dl>';
					});
			   $("#wodezhuji").append(wodezhuji);
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	
	 }else{
	 	//alert("未登录");
	 }
	
}


function shangpingherf(ids){
	window.location.href="7.0.0goods_detail.html?id="+ids;
	
}

 var mygoodsid="";
//查询是否收藏过
function shifoushouchang(){
	      if(uuuuid!=""){
						$.ajax({
						url: urlcore + "/api/goods/isCollection2?id="+id+"&userId="+uuuuid,///myCollection/addOrCancelMyCollection?goodsId=' + goodsId,
						type: "get",
						dataType: 'json',
						contentType: "application/json;charset=utf-8",//goods/isCollection2?id="+id+"&userId="+uuuuid,
						success:function(data){
							
							if(data.success == true) {
								 var da=data.data;
								 
										if(da==null){
									 $("#shifoushouchangs").attr("src","images/detail_bottom04.png");
										}else{
											if(da.status==1){
								 $("#shifoushouchangs").attr("src","images/detail_bottom05.png");
							 }else{
								$("#shifoushouchangs").attr("src","images/detail_bottom04.png");
							 }
										}
							}else{
								$("#shifoushouchangs").attr("src","images/detail_bottom04.png");
							}
					},
					error:function() {
						alert("error");
					}
				});	
	 }
}
var shopidss="";
//收藏 
//  function  updateCollection() {
//     var that = this;
//     var goodsId = that.data.datas.goods.id;
//     wx.setStorageSync("nowGoodsId", goodsId)
//     httpsUtils.getData({
//       _url: app.globalData._url + '/myCollection/addOrCancelMyCollection?goodsId=' + goodsId,
//       data: '',
//     }, function (json) {
//       console.log(json);
//       if (json.data && json.success) {
//         if (json.data.status == 1) {
//           wx.showToast({
//             title: '收藏成功',
//             icon: 'none'
//           })
//         } else {
//           wx.showToast({
//             title: '取消收藏成功',
//             icon: 'none'
//           })
//         }
//         that.setData({
//           isCollection: json.data.status,
//         })
//       }
//       if (json.success == false && json.code == 'OVERTIME') {
//         wx.navigateTo({
//           url: '../wxLogin/wxLogin?type=3&isTab=false',
//         })
//       }
//     })
//   }
//去领取优惠券
// function gotocounpon(){
// 	
// 	   if(uuuuid!=""){
// 	   	if(shopidss!=""){
// 	   		window.location.href="7.0coupon.html?id="+shopidss;
// 	   	}
// 	   		
// 	   }else{
// 	   	alert("未登录/或登录超时");
// 	   }
// 
// 	
// }
// 




function shouchang(goodsId){
  var goods=sessionStorage.getItem('id');
	if(uuuuid!=''){
		
	var imgs=$("#shifoushouchangs").attr("src");
	if(imgs=="images/detail_bottom05.png"){
    $("#shifoushouchangs").attr("src","images/detail_bottom04.png");
    $.ajax({
			url: urlcore + "/api/myCollection/addOrCancelMyCollection?goodsId=" + goods, 
			type: "get",
			contentType: "application/json;charset=utf-8",//myCollection/update
			dataType: "json",
			success: function(data) {
				 console.log(data)
				if(data.success == true) {
					slelectnot();
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					if(thisUrl.indexOf('login.html') <= -1) {
						//top.window.location.href = "login.html";
					}
				} else {
					alert(data.msg);
				}
			},
			error: function() {
				alert("error");
			}
	  });
	}else if(imgs=="images/detail_bottom04.png"){
		// console.log(data)
		  $("#shifoushouchangs").attr("src","images/detail_bottom05.png");
         $.ajax({
		url: urlcore + "/api/myCollection/update", //userid
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			userId:uuuuid,
			goodsId:id,
			status:1
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
	}else{
		
		  $("#shifoushouchangs").attr("src","images/detail_bottom04.png");
			
	}
	}
}




var shopId="";
function slelectnot(){
		 $("#slideBox").html("");
		 $("#shangpingxiangqing").html("");
		
		$.ajax({
        url: urlcore + "/api/goods/particulars?id="+id,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) { 
				if(data.success == true) {
					  $('#img_details').html("");
				    var da=data.data;
				     var shangpingxiangqing="";
				      if(da.goods.goods_simple!=null && da.goods.goods_simple!=""){
				          shangpingxiangqing+='<center><h5 class="miaoshu">描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述</h5></center>';
				           shangpingxiangqing+='<center><h6 style="margin-bottom:10px;line-height:25px;color:#000">'+da.goods.goods_simple+'</h6></center>';
				        }
				    var yanshe="无";
				    var chicun="无";
				    var shuxing="无";
				      if(da.propertyList!=null && da.propertyList!=""){
				      	yanshe="";
				      	chicun="";
				      	shuxing="";
				      	var svu=0;
								 yanshe+=da.colorName;
								 chicun+=da.sizeName;
				      	  shangpingxiangqing+='<center><h5 class="miaoshu">参&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数</h5></center>';
				      	   $.each(da.propertyList, function(s,n) {
				           svu++;
				              if(da.propertyList.length==svu){
				              	       if(da.propertyList!=null && da.propertyList!=""){
				              	       	      	     	 $.each(da.propertyList, function(y,q) {
				         shuxing+="<div class='mianliao'><div style='width:70%;'><h6>"+q.oneProperty+":&nbsp;&nbsp;&nbsp;"+q.twoProperty+'</h6></div></div>';
                          });
				              	       }
				        
				              
				              }
				    
				      	   });
				      	  shangpingxiangqing+="<div class='yanse'><div style='width:70%;'><h6 style='line-height:1.5'>颜色 :"+yanshe+"</br></h6></div></div>";
				         shangpingxiangqing+="<div class='yanse'><div style='width:70%;'><h6>尺码 :"+chicun+"</h6></div></div>";
				         shangpingxiangqing+=shuxing;
				 
				        }
				   $("#shangpingxiangqing").append(shangpingxiangqing);
				    //分类按钮
				    shopidss=da.shopinfo.id;
			
				      shopId=da.shopinfo.id;
				      var headImg=da.goods.goods_url;
				           var imgStr1='<div class="bd" id="lunbo" >'+'<ul >';
			var goodsimg="";
			var susu=1;
				goodsimg+='<div style="height:100%;margin-bottom:-5.7%"><img onerror="errorImg(this)"  src="'+da.goods.cover_url+'" style="height: 180%;width: 100%; margin-bottom:10px;"></div><div></div></br>';
				 imgStr1 +='<li><img onerror="errorImg(this)" data-preview-src="" data-preview-group="1"  style="margin: 0 auto;min-height:100%;width: 100%;max-height:232%;background-size:contain" src="'+da.goods.cover_url+'" /></li>';
							
					 if(headImg != null && headImg != '') {
						var imgarr1 = headImg.split("***");
						$.each(imgarr1, function(index, value) {
							susu++;
						 imgStr1 +='<li><img onerror="errorImg(this)" data-preview-src="" data-preview-group="1" style="margin: 0 auto;min-height:100%;max-height: 232%;width: 100%;background-size:contain" src="'+value+'" /></li>';
						goodsimg+='<div ><img onerror="errorImg(this)" style="height: 180%;width: 100%; margin-bottom:10px;" src="'+value+'"></div><div> </div>';
						});
						
					}
					 imgStr1 +='</ul>'+
'		</div>'+
'		<div class="hd">'+
'			<ul></ul>'+
'		</div>';
       $("#goodsimg").append(goodsimg);
       $("#slideBox").append(imgStr1);
					 
	$(function(){
	TouchSlide({
		slideCell:"#slideBox",
		titCell:".hd ul", //开启自动分页 autoPage:true ，此时设置 titCell 为导航元素包裹层
		mainCell:".bd ul", 
		effect:"leftLoop", 
		autoPage:true,//自动分页
		autoPlay:true //自动播放
	});
						}); 
					 
var timeStr="";
var goodTime=da.goods.upt_datetime;
var nowTime = Date.parse(new Date());
    var subTime = (nowTime - goodTime) / 1000;
    var timeStr = '';
    if (subTime < 60) {
      timeStr = '刚刚';
    } else if (parseInt(subTime / 60) < 60) {
      timeStr = parseInt((subTime / 60)) + '分钟前';
    } else if (parseInt(subTime / (60 * 60)) < 24) {
      timeStr = parseInt(subTime / (60 * 60)) + '小时前';
    } else if (parseInt(subTime / (60 * 60 * 24)) < 30) {
      timeStr = parseInt(subTime / (60 * 60 * 24)) + '天前';
    } else if (parseInt(subTime / (60 * 60 * 24 * 30)) < 12) {
      timeStr = parseInt(subTime / (60 * 60 * 24 * 30)) + '月前';
    } else {
      timeStr = parseInt(subTime / (60 * 60 * 24 * 30 * 12)) + '年前';
    }
   
    timeStr= timeStr

	var jianjie='<h2>'+da.goods.goods_title+'</h2>'+
	'<ul class="clearfix">'+
		'<li>'+
			'<span>'+da.goods.trade_number+'</span>'+
			'<span>-'+da.goods.pack_number+'件</span>'+
			'<div class="dabao"><span class="bao" style="font-size: 12px;color:#FD900F;">拿货</span><h5 style="display:inline-block">&yen;'+da.goods.trade_price+'</h5></div>'+
			'<em>'+timeStr+'更新</em>'+
		'</li>'+
		'<li>'+
			'<span>'+da.goods.pack_number+'件及其以上</span>'+
			'<div class="dabao"><span class="bao" style="font-size: 12px;color:#FD900F;">打包</span><h5 style="display:inline-block">&yen;'+da.goods.pack_price+'</h5></div>'+
			'<em>已卖出'+da.goods.sale_num+'件</em>'+
		'</li>'+
		'<li style="text-align:center">'+
			'<em style="display:inline-block;line-height:80px;">'+da.goods.look_time+'次浏览</em>'+
		'</li>'+
	'</ul>';
	       $("#jianjie").append(jianjie);  //产品规格信息完结
		
		 
      //    alert(JSON.stringify());
          var dikou='<ul>';
          if(da.shopinfo.openGold==1){
            dikou+='<li><img src="images/di.png" />可用金币抵扣'+da.goods.gold_rate+'%</li>';
          }else{
            dikou+='<li><img src="images/di.png" />不参与金币抵扣活动</li>';
          }
		      if(da.shopinfo.goldexchange==0 || da.shopinfo.goldexchange==null){
						dikou+='<li><img src="images/zeng.png" />不赠送金币</li>';
					}else{
						dikou+='<li><img src="images/zeng.png" />每件最高赠送金币'+da.shopinfo.goldexchange+'个</li>';
					}
			
				 if(da.shopinfo.mixNumber==0){
							dikou+='<li><img src="images/pi.png" />不支持采购混批</li>';
				 }else{
							dikou+='<li><img src="images/pi.png" />全店满'+da.shopinfo.mixNumber+'件可混批采购</li>';
				 }
		dikou+='</ul>';
           $("#dikou").append(dikou);  //抵扣优惠完结
           var pingjia='<div class="Pingjia_title">'+
           '<a  onclick="dianjipingaji('+da.goods.id+','+da.shopinfo.id+','+da.commentList.length+')">共'+da.commentList.length+'条评价</a>'+
           '</div>';
	         $.each(da.commentList,function(m,z){
						 
	         	 var dar=new Date(z.gmt_datetime).pattern("yyyy-MM-dd hh:mm");
	         	  pingjia+='<div class="sell_pingjia_xinxi">'+
							'<div class="sell_pingjia_tu">'+
								'<img src="'+z.head_img+'" />'+
							'</div>'+
							'<div class="sell_pingjia_wenzi">'+
								'<div class="sell_pingjia_mz clearfix">'+
									'<h5>'+z.user_name+'</h5>'+
									'<div class="fr">';
												 for(var i=0;i<z.service_level;i++){
													pingjia+='<img src="images/star.png" />';
												 }
										pingjia+='<i>'+z.quality_level+'分</i>'+
									'</div>'+
								'</div>'+
								'<span>'+dar+'</span>';
			if(z.is_img==1){
				     var imgarr1 = z.comment_img.split("***");
				      $.each(imgarr1, function(index, value) {
								pingjia+='<img src="'+value+'" data-preview-src="" class="tupian" data-preview-group="1" />';
								});
			  }
			pingjia+=
			'<p>'+z.comment_content+'</p>'+
		'</div>'+
	'</div>';
	             return false;
	         });
	
                   $("#pingjia").append(pingjia);  //评价完结
									 sessionStorage.setItem('id',da.shopinfo.id)
                   var dianpu=
												 '<dl>'+
											'<a href="#" >'+
												'<dt>'+
													'<img src="'+da.shopinfo.headImg+'" />'+
												'</dt>'+
												'<dd>'+
													'<span>'+da.shopinfo.storeName+'</span><p  style="width: 84px;margin-right: 5px;" onclick="quanbushangping('+da.shopinfo.id+')">全部商品<strong>('+da.size+')</strong></p><p class="p1"  onclick="botel('+da.shopinfo.phone+')">联系店家</p>'
													  var creditLevel=da.shopinfo.creditLevel;
													  var levelType = parseInt(creditLevel / 5);
														var levelTimes = parseInt(creditLevel % 5);
														var levelArray = [];
														for (var i = 0; i < levelTimes; i++) {
															levelArray.push(levelType);
														}
													if(levelType ==0){
                             dianpu+='<img src="images/hongxin.png" class="dengji">'
													}else if(levelType ==1){
														dianpu+='<img src="images/zuangshi.png"  class="dengji">'
													}else if(levelType ==2){
														dianpu+='<img src="images/huangguang.png"  class="dengji">'
													}else{
														console.log(5)
													}
													dianpu+='<h5>'+da.shopinfo.province+da.shopinfo.city+da.shopinfo.county+'</h5>'+
															'</dd>'+
														'</a>'+
													'</dl>';
												
													
							$('#dianpu').append(dianpu);   //店铺信息
								 //商品详情图片还没添加 轮播图还没做
							    shifoushouchang();
								  shouchang(da.goods.id)

							    // updateCollection();
								
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});
		
		zhuji();
        }
function fenlei(){
	// console.log(123)
		window.location.href="6.2.0dianpu_fenlei.html?id="+shopidss;
}
function quanbushangping(shopid){
	window.location.href="6.0.0dianpu.html?id="+shopid;
}

function dianjipingaji(goodsid,shopid,list){
	
	if(list>0){
		window.location.href="7.1.0goods_pingjia.html?goodId="+goodsid+"&shopId="+shopid;
	}else{
		sessionStorage.setItem('idd',goodsid)
		sessionStorage.setItem('sidd',shopid)
		window.location.href="7.1.0goods_pingjia.html?goodId="+goodsid+"&shopId="+shopid;
		//alert('暂无评价')
	}
	
}
//联系卖家
 function botel(tel){
	 window.location.href="tel:"+tel;
 }
function addtianjia(){
	alert('请下载服装基地app');
	// window.location.href="7.2.0goods_guige.html?id="+id;
}
//引入微信js
function youhuijuan(){
		$.ajax({
        url: urlcore + "/api/coupon/getCouponList2?shopId="+shopId,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
			       var youhui='<div class="publiu">'+
				'<h2>店家优惠券</h2>'+
				'<ul>';
                   if(data.data!=null && data.data!=""){
                      $.each(data.data, function(y,n) {
           youhui+= '<li>'+
						'<h3>'+n.couponname+'</h3>'+
						'<p>满'+n.limitMoney+'减'+n.saveMoney+'</p>'+
						'<a onclick="linquyouhui(this)" class="'+n.shopId+'" name="'+n.id+'">领取优惠券</a>'+
						'<input type="text" class="'+n.limitMoney+'" value="'+n.saveMoney+'"/>'+
					'</li>';    
                      });
                   }else{
                   	  youhui+= '<li>'+
						'<h3>该店铺未发布优惠劵</h3>'+
					'</li>';    
                   }
                   youhui+='</ul>'+
				   '<h6>关闭</h6>'+
			        '</div>';
			  $("#youhuijuanshuoming").append(youhui);
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					}else{
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});
		
}


function linquyouhui(te){
	 var counptid=$(te).attr("name");
	 var shopId=$(te).attr("class");
	 var jian=$(te).next().val(); //减多少
	 var man=$(te).next().attr("class");  //满多少
	 if(uuuuid!=""){
	 	    $.ajax({  
        url : urlcore + "/api/userCoupon/add2",
        type : "post",  
        contentType: "application/json;charset=utf-8",
        data : JSON.stringify({
        "userId":uuuuid,	
        "shopId":shopId,
        "couponId":counptid,
        "limitMoney":man,
        "saveMoney":jian,
        "type":1
        }),
        dataType: "json",
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
        	if(data.success == true) {
        		//window.location.href = document.referrer
        		 alert("以存入优惠卷列表");  
        	}else{
        		alert(data.msg);
        	}
        },
        error:function(){  
            alert("修改失败");  
        }  
    });     
	 }else{
	 	//alert("未登录");
	 }
}





function zhuji(){

	 if(uuuuid!=""){
	 	    $.ajax({  
        url : urlcore + "/api/myFoot/add2",
        type : "post",  
        contentType: "application/json;charset=utf-8",
        data : JSON.stringify({
        "userId":uuuuid,	
        "goodsId":id,
        }),
        dataType: "json",
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
        	if(data.success == true) {
        	}else{
        	//	alert(data.msg);
        	}
        },
        error:function(){  
           // alert("修改失败");  
        }  
    });     
	 }else{
	 //	alert("未登录");
	 }
}